import {findAll, findOrderGoods, findReceiverByOrderId, GetdataDictionary, pageInfo} from "@/api/b2c/order";
import pickerOptions from "@/utils/date";

export default {
    name: "index",
    data() {
        return {
            size: '',
            dialogFormVisible: false,
            payTypeList: [],
            orderActionlist: [],
            orderTypeList: [],
            orderStatusList: [],
            businessTypeList: [],
            orderList: [],
            orderProductList: [],
            goodList: [],
            formData: {},
            excelIdlIST: {
                id: ``,
            },
            receiverInfo: [],
            idList: [],
            multipleSelection: [],
            total: 0,
            pickerOptions: pickerOptions,
            searchParams: {
                currentPage: 1,
                pageSize: 8,
                id: ``,
                orderType: ``,
                paymentMethodId: ``,
                orderAction: ``,
                businessType: ``,
                orderStatus: ``
            },
            table: {},
        }
    },
    methods: {
        findOrderList() {
            findAll().then(response => {
                console.log(response)
                this.orderList = response;
                console.log(this.orderList)
            })
        },
        //分页查询
        async pageFind() {
            let response = await pageInfo(this.searchParams)
            this.total = response.total;
            this.orderList = response.data;
        },
        //页面变化
        currentPageChange(currentIndex) {
            // console.log(currentIndex);
            this.searchParams.currentPage = currentIndex;
            this.pageFind()
        },
        //选择时间
        chooseTime() {
            this.searchParams.startTime = this.pickerOptions.startDate[0];
            this.searchParams.endTime = this.pickerOptions.startDate[1];
        },
        //重置
        resetForm() {
            this.searchParams = {
                currentPage: 1,
                pageSize: 8,
            }
            this.pickerOptions.startDate = '';
            this.pageFind();
        },
        //数据字典
        async querydic() {
            //1.订单动作 2 订单状态 3 业务类型 4 配送方式  5 支付方式  6订单分类订单类型 7 退货原因 ',
            let result = await GetdataDictionary();
            console.log(result)
            this.orderActionlist = result[1]
            this.orderStatusList = result[2]
            this.businessTypeList = result[3]
            this.payTypeList = result[5]
            this.orderTypeList = result[6]
            // console.log(this.orderTypeList)
        },
        //根据orderId查询
        async findOrderById(row) {
            this.formData = await row
            this.goodList = await findOrderGoods(row.id)
            await this.findReceive(row)
            console.log(this.receiverInfo);
            // await findeOrderByIdList(this.idList)
        },
        //根据订单id查询收货人信息
        async findReceive(row) {
            this.receiverInfo = await findReceiverByOrderId(row.id)
        },
        //选中数据
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //批量导出
        async selectBy() {
            this.idList = this.multipleSelection.map(item => item.id)
            window.location.href="http://localhost:8088/order/exportExcel/"+this.idList
            // await excel(this.idList)
            await this.pageFind()
        },
        open2() {
            this.$message({
                message: '已经导出到桌面',
                type: 'success'
            });
        },
        show() {
            this.$message("查看商品详情")
        },
        async addOrder() {
            location.href = "/order/addOrder"
        },

        //过滤
        async backOrder() {
            location.href = "/order"
        },
        //查看订单详细信息
        lookOrderInfo(row) {
            location.href = "/order/orderInfo/" + row.id
        },
        area(){
            location.href="/order/area"
        }

    },
    created() {
        this.pageFind()
        this.querydic()
    }
}